<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>实例成员</title>
</head>
<body>
  <script>
    class Person {
      constructor() {
        // 这个例子先使用对象包装类型定义一个字符串
        this.name = new String('Jack');

        this.sayName = () => console.log(this.name);

        this.nicknames = ['Jake', 'J-Dog'];
      }
    }

    let p1 = new Person(),
      p2 = new Person();

    p1.sayName();  // String {"Jack"}
    p2.sayName();  // String {"Jack"}

    console.log(p1.name === p2.name);  // false
    console.log(p1.sayName === p2.sayName);  // false
    console.log(p1.nicknames === p2.nicknames);  // false

    p1.name = p1.nicknames[0];
    p2.name = p2.nicknames[1];

    p1.sayName()  // Jake
    p2.sayName()  // J-Dog
  </script>
</body>
</html>